package main

import "fmt"

// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
	i := 0;
	num1, num2 := 0, 1
	return func() int{
		defer func (){
			i++
		}()
		switch {	
		case i==0:
			return num1
		case i==1:
			return num2
		default :
			num3 := num1 + num2
			num1, num2 = num2, num3
			return num3
		}
	}
}

func main() {
	f := fibonacci()
	for i := 0; i < 10; i++ {
		fmt.Println(f())
	}
}
